package com.gvfish.web.jsf;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;

import com.google.appengine.api.datastore.Category;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;

public class GCatKeyConverter implements Converter {

	@Override
	public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) {
		Key key = KeyFactory.createKey(Category.class.getSimpleName(), Long.valueOf(arg2));
		return key;
	}

	@Override
	public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) {
		System.out.println(arg2.getClass());
		Key key = (Key)arg2;
		return String.valueOf(key.getId());
	}


}
